<?php
//The next comment block is for PHPDocumentor
/**
 * Conference Registration - Registration for conferences
 * 
 * Admin menu option:
 * Setup a new conference
 * 
 * @author Kevin van Haaren (kevin@vanhaaren.net)
 * @copyright 2006 Kevin van Haaren, US
 * @package CONFREG
 * @subpackage Admin_Function
 * 
 */

/**
* Do all the declarations etc needed by an admin page
*/
include_once "adminheader.inc";


echo "Adding conference to database.<br />";

// the date fields are returned as arrays
// the cleanInput function purges arrays
// we need to save those fields (and clean them)
// manually
$dateFields = array (	'confstart',
						'confend',
						'regstart',
						'regend',
						'early_cutoff');

foreach ($dateFields as $key => $value) {
	// use intval to force strings to integers, this is done to
	// clean the input from the form
	$year = intval(substr($_POST[$value]['date'],0,4));
	$month = intval(substr($_POST[$value]['date'],5,2));
	$day = intval(substr($_POST[$value]['date'],8,2));
	
	$_POST[$value] = mktime(0, 0, 0, $month, $day, $year) + intval($_POST[$value]['time']);
}

$cleanPost = cleanInput($_POST);

// remove $ and , from money amounts
// this is US specific
$cleanPost['early_cost'] = str_replace(array('$',','),'',$cleanPost['early_cost']);
$cleanPost['late_cost'] = str_replace(array('$',','),'',$cleanPost['late_cost']);

// add the cleaned data to the database
$conf_insert = 'INSERT INTO ' . $xoopsDB->prefix('confreg_conferences') .
				' SET title=' . $xoopsDB->quoteString(substr($cleanPost['title'],0,128)) .
				', location=' . $xoopsDB->quoteString(substr($cleanPost['location'],0,128)) .
				', help_email=' . $xoopsDB->quoteString(substr($cleanPost['helplink'],0,128)) .
				', confirm_offset=' . intval($cleanPost['invoffset']) .
				', schedlink=' . $xoopsDB->quoteString(substr($cleanPost['schedlink'],0,128)) .
				', start_date=FROM_UNIXTIME(' . intval($cleanPost['confstart']) . ')' .
				', end_date=FROM_UNIXTIME(' . intval($cleanPost['confend']) . ')' .
				', reg_start=FROM_UNIXTIME(' . intval($cleanPost['regstart']) . ')' .
				', reg_end=FROM_UNIXTIME(' . intval($cleanPost['regend']) . ')' .
				', early_cost=' . floatval($cleanPost['early_cost']) .
				', late_cost=' . floatval($cleanPost['late_cost']) .
				', early_cutoff=FROM_UNIXTIME(' . intval($cleanPost['early_cutoff']) . ')';

echo "Query built.<br />";

$insert_res = $xoopsDB->query($conf_insert);

if (!$insert_res) {
	echo "<p>Error occured inserting extra!";
	// debug info
	echo "<p>Error Number:" . $xoopsDB->errno() . "<br \>";
	echo "<p>Error:" . $xoopsDB->error() . "<p>";
//	echo '<p><code style="text-align:left;>' . $db_insert . "</code>";
//	echo '<p><code style="text-align:left;>' . var_dump($cleanPost) . "</code>";
} else {
	$confid = $xoopsDB->getInsertId();
	echo 'Conference ' . $cleanPost['title'] . ' has been created. Conference id is ' . $confid . '<br />';
	echo '<a href="admenu0.php">Return to Conference Setup</a>';
}

xoops_cp_footer();

/*
 * This file was generated by XBS ModGen, (c) 2006 A Kitson, UK. See http://xoobs.net
 * ModGen is a Module Code Generator for the Xoops CMS.  See http://xoops.org
 */
?>
